/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 13-11-4
 * Time: 下午3:48
 * To change this template use File | Settings | File Templates.
 */
Ext.define("byb.view.grid.BaseGridPanel",{
     extend: "Ext.grid.Panel",
     columns:[],
     initComponent:function(){
        this.forceFit=true;
        this.scrollOffset=0;
        this.header=this.buildHeader();
        this.stripeRows=true;
        this.columns=this.buildColumns();
        this.dockedItems=this.buildBars();
        this.callParent(arguments);
     },
     buildColumns:function(){
         return [];
     },
     buildHeader:function(){

     },
     buildFooter:function(){
         return {
            xtype:"pagingtoolbar",
            store:this.store,
            dock:"bottom",
            displayInfo:true
         };
     },
     getOperations:function(){
         //操作条放置在表格的什么位置
         //都有什么操作,可以配置多个操作
         return [{dock:"top",operations:[]}];
     },
     buildBars: function(){
         var bars=this.getOperations();
         if(bars.length==0){
            return bars;
         }
         var myOperationBars=new Array();
         myOperationBars.push(this.buildFooter());
         for(var i=0;i<bars.length;i++){
             var bar=bars[i];
             var dock=bar.dock;
             var operations=bar.operations;
             var items=new Array();
             for(var j=0;j<operations.length;j++){
                 var operation=operations[j];
                 if(operation==byb.Constant.TabBarOperationAdd){
                     items.push({
                         text:"新增",
                         iconCls:"icon-add",
                         action:byb.Constant.TabBarOperationAdd+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationModify){
                     items.push({
                         text:"修改",
                         iconCls:"icon-edit",
                         action:byb.Constant.TabBarOperationModify+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationDelete){
                     items.push({
                         text:"删除",
                         iconCls:"icon-del",
                         action:byb.Constant.TabBarOperationDelete+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationPrint){
                     items.push({
                         text:"打印",
                         iconCls:"icon-print",
                         action:byb.Constant.TabBarOperationPrint+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationCancel){
                     items.push({
                         text:"取消",
                         iconCls:"icon-cancel",
                         action:byb.Constant.TabBarOperationCancel+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationResetPassword){
                     items.push({
                         text:"重置密码",
                         iconCls:"icon-password-reset",
                         action:byb.Constant.TabBarOperationResetPassword+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Month){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Month+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Quarter){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Quarter+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Year){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Year+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Span){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Span+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Sales_Month){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Sales_Month+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Sales_Quarter){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Sales_Quarter+"_"+i
                     });
                 }else if(operation==byb.Constant.TabBarOperationExport_Sales_Year){
                     items.push({
                         text:"导出",
                         iconCls:"icon-export",
                         action:byb.Constant.TabBarOperationExport_Sales_Year+"_"+i
                     });
                 }
             }
             if (items.length != 0) {
                 myOperationBars.push({
                     xtype:"toolbar",
                     dock:dock,
                     defaultType:"button",
                     items:items
                 });
             }
             
             return  myOperationBars;
         }

     },
     getPagingBar:function(){
        return this.down("pagingtoolbar");
     }
});
